package com.example.nettydemo.config;

import com.example.nettydemo.game.Room;
import com.example.nettydemo.server.NettyServer;
import com.example.nettydemo.server.NettyServerInitializer;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.support.ConversionServiceFactoryBean;
import org.springframework.core.convert.ConversionService;
import org.springframework.core.convert.converter.Converter;

import java.util.HashSet;
import java.util.Set;

/**
 * @author WZW
 * @date 2020/5/6
 */
@Configuration
public class NettyConfig {

    @Bean
    public NettyServer nettyServer(NettyServerInitializer nettyServerInitializer){
        NettyServer nettyServer = new NettyServer(12345);
        nettyServer.setNettyServerInitializer(nettyServerInitializer);
        return nettyServer;
    }

    @Bean
    public ConversionService conversionService(AtomicIntegerConvert AtomicIntegerConvert) {
        ConversionServiceFactoryBean bean = new ConversionServiceFactoryBean();
        Set<Converter<?,?>> converters = new HashSet<>();
        converters.add(AtomicIntegerConvert);
        bean.setConverters(converters);
        bean.afterPropertiesSet();
        return bean.getObject();
    }

}
